#include "StdAfx.h"
#include "UnitTest++.h"

#include "ResourceManager.h"
#include "Resource.h"

//////////////////////////////////////////////////
//ResourceManagerTest
//////////////////////////////////////////////////

TEST(TestResourceManagerConstructor)
  {
  ResourceManager<Resource<int>>* resource_manager = new ResourceManager<Resource<int>>();
  CHECK_EQUAL(resource_manager->GetNumberOfResources(), 0);
  }

//------------------------------------------------

TEST(TestResourceManagerAddResource)
  {
  ResourceManager<Resource<int>>* resource_manager = new ResourceManager<Resource<int>>();
  CHECK_EQUAL(resource_manager->GetNumberOfResources(), 0);
  
  resource_manager->AddResource("c:\\test\\", "data_1");
  CHECK_EQUAL(resource_manager->GetNumberOfResources(), 1);
  
  resource_manager->AddResource("c:\\test\\", "data_2");
  CHECK_EQUAL(resource_manager->GetNumberOfResources(), 2);
  
  resource_manager->AddResource("c:\\test\\", "data_1");
  CHECK_EQUAL(resource_manager->GetNumberOfResources(), 2);
  }

//------------------------------------------------

TEST(TestResourceManagerGetResource)
  {
  ResourceManager<Resource<int>>* resource_manager = new ResourceManager<Resource<int>>();
  CHECK(!resource_manager->GetResource("", "", false));

  Resource<int>* res_1 = resource_manager->AddResource("c:\\test\\", "data_1");
  Resource<int>* res_2 = resource_manager->AddResource("c:\\test\\", "data_2");  

  CHECK_EQUAL(resource_manager->GetResource("c:\\test\\", "data_1"), res_1);  
  CHECK_EQUAL(resource_manager->GetResource("c:\\test\\", "data_2"), res_2);

  Resource<int>* res_3 = resource_manager->AddResource("c:\\test\\", "data_2");
  CHECK_EQUAL(resource_manager->GetResource("c:\\test\\", "data_2"), res_3);
  CHECK_EQUAL(resource_manager->GetResource("c:\\test\\", "data_2"), res_2);

  Resource<int>* res_4 = resource_manager->GetResource("c:\\test\\", "data_3", true);
  CHECK(res_4);
  }

//------------------------------------------------

TEST(TestResourceManagerRemoveResource)
  {
  ResourceManager<Resource<int>>* resource_manager = new ResourceManager<Resource<int>>();  

  Resource<int>* res_1 = resource_manager->AddResource("c:\\test\\", "data_1");
  Resource<int>* res_2 = resource_manager->AddResource("c:\\test\\", "data_2");  
  Resource<int>* res_3 = resource_manager->AddResource("c:\\test\\", "data_2");

  resource_manager->RemoveResource(res_2);

  CHECK_EQUAL(resource_manager->GetNumberOfResources(), 2);
  CHECK_EQUAL(resource_manager->GetResource("c:\\test\\", "data_2"), res_2);  
  CHECK_EQUAL(resource_manager->GetResource("c:\\test\\", "data_2"), res_3);

  resource_manager->RemoveResource(res_3);

  CHECK_EQUAL(resource_manager->GetNumberOfResources(), 1);
  CHECK(!resource_manager->GetResource("c:\\test\\", "data_2"));
  CHECK(!resource_manager->GetResource("c:\\test\\", "data_2"));
  }

//------------------------------------------------

//////////////////////////////////////////////////